#include "background.h"
#include "warp.h"
#include "graphics.h"
#include "tag.h"
#include "images_diffuse.h"

#include <math.h>

declare_body(background, {
	float position;
})

declare_tick(background, {
	float speed = 1 + warp_fac() * 6;
	self->position -= speed;
	self->position = fmod(self->position, 150);
})

declare_draw(background, {
	int frame = (int)(warp_fac() * 4);
	if(frame > 3) frame = 3;
	
	draw_sprite_f(&sprite_background, 0, self->position,       frame);
	draw_sprite_f(&sprite_background, 0, self->position + 150, frame);
})

declare_head(background)

entity *make_background() {
	entity *ent = ent_new();
	ent->tag = TAG_BACKGROUND;
	
	background *b = c_new(background);
	b->position = 0;
	add_component(ent, b);
	
	return ent;
}
